package win.demonlegion.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import win.demonlegion.service.inte.ByteCacheService;

import java.util.List;

@Service("byteCacheService")
public class ByteCacheServiceImpl implements ByteCacheService {
    private static final Logger logger = LoggerFactory.getLogger(ByteCacheServiceImpl.class);

    @Autowired
    private RedisTemplate<String, byte[]> redisTemplate;

    @Override
    public byte[] get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public void set(String key, byte[] value) {
        redisTemplate.opsForValue().set(key, value);
    }

    @Override
    public long getListSize(String key) {
        return redisTemplate.opsForList().size(key);
    }

    @Override
    public List<byte[]> getSubList(String key, long start, long end) {
        return redisTemplate.opsForList().range(key, start, end);
    }

    @Override
    public List<byte[]> getList(String key) {
        return getSubList(key, 0, -1);
    }

    @Override
    public long rightPushValue(String key, byte[] value) {
        return redisTemplate.opsForList().rightPush(key, value);
    }
}
